import { useUserStore } from '@/stores/user';
export function downloadFile(path, name='') {
  const userStore = useUserStore()
    const token = userStore.accessToken
    const xhr = new XMLHttpRequest();
    xhr.open('get', path);
    xhr.responseType = 'blob';
    // xhr添加token
    xhr.setRequestHeader('Authorization', token);
    xhr.send();
    xhr.onload = function () {
      if (this.status === 200 || this.status === 304) {
        const fileReader = new FileReader();
        fileReader.readAsDataURL(this.response);
        fileReader.onload = function () {
          const a = document.createElement('a');
          a.style.display = 'none';
          a.href = this.result;
          a.download = name;
          document.body.appendChild(a);
          a.click();
          document.body.removeChild(a);
        };
      }
    };
  }
  